﻿using System;
using System.Data.Entity;
using AceSoft.RetailPlus.Security;

namespace AceSoft.RetailPlus
{
    public class SysModuleMock
    {
        public SysModuleMock()
        {

            Security.Security _Security = new Security.Security();

            DbSet<SysModule> _SysModules = _Security.SysModules;

            Console.WriteLine("Available sysmodules");
            foreach (SysModule _SysModule in _SysModules)
            {
                Console.WriteLine(" ID: {2}   SysModule Code: {0}      Name: {1}", _SysModule.Code, _SysModule.Name, _SysModule.ID);
            }

            Console.WriteLine("Deleting sysmodules");
            foreach (SysModule _SysModule in _SysModules)
            {
                if (_SysModule.ID == 0)
                {
                    Console.WriteLine(" SysModule Code: {0} is a default and cannot be deleted.", _SysModule.Code);
                }
                else
                {
                    _SysModules.Remove(_SysModule);
                    Console.WriteLine(" SysModule Code: {0} deleted.", _SysModule.Code);
                }
            }

            Console.WriteLine("Adding sysmodules");
            for (int x = 0; x <= 100; x++)
            {
                _SysModules.Add(new SysModule { ID = x, Code = "Code" + x, Name = "SysModule Name " + x });
                Console.WriteLine(" SysModule Code: {0} added.", "Code" + x);
                _Security.SaveChanges();
            }

            Console.WriteLine("Relisting sysmodules");
            foreach (SysModule _SysModule in _SysModules)
            {
                Console.WriteLine(" ID: {2}   SysModule Code: {0}      Name: {1}", _SysModule.Code, _SysModule.Name, _SysModule.ID);
            }
        }
    }
}
